package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.app.util.UserContext;
import cn.wolfcode.trip.base.domain.Letter;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.service.ILetterService;
import cn.wolfcode.trip.base.service.ISysnoticeService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("sysnotice")
public class SysnoticeController {

    @Autowired
    private ISysnoticeService sysnoticeService;

    // 查询未读私信数量
    @GetMapping("/getSysnoticeByState")
    public Object getMessagesByState(Long userId,HttpServletRequest request, HttpServletResponse response) {
        int data = sysnoticeService.getSysnoticeByState(userId);
        return data;
    }

    // 查询所有私信
    @GetMapping("/getSysnotices")
    public Object getLetters(Long userId) {
        return sysnoticeService.getSysnotices(userId);
    }

    // 修改私信状态
    @PostMapping("/setSysnoticeState")
    public JSONResult setLetterState(int state,Long userId) {
        JSONResult result = new JSONResult();
        try {
            sysnoticeService.setSysnoticeState(state,userId);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
}
